package org.ling.xuan.pannel;

import com.intellij.ui.components.JBPanel;
import com.intellij.ui.components.JBScrollPane;
import com.intellij.ui.table.JBTable;
import org.ling.xuan.compoment.CustomTableCellEditor;
import org.ling.xuan.entity.mo.SvnCommitCheck;
import org.ling.xuan.table.SvnCommitCheckTableModel;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;

public class SvnCommitCheckPanel extends JBPanel {

    private final JBTable successTable = new JBTable();
    private final JBTable warnTable = new JBTable();
    private final JBTable errorTable = new JBTable();
    List<SvnCommitCheck> success = new ArrayList<>();
    List<SvnCommitCheck> warn = new ArrayList<>();
    List<SvnCommitCheck> error = new ArrayList<>();

    public SvnCommitCheckPanel(List<SvnCommitCheck> commitChecks) {
        setLayout(new GridLayout(3, 1));
        commitChecks.forEach(a -> {
            if (a.getCheckStatus() == 1) {
                success.add(a);
            } else if (a.getCheckStatus() == 0) {
                error.add(a);
            } else {
                warn.add(a);
            }
        });
        JBPanel successPanel = new JBPanel();
        successPanel.setLayout(new BorderLayout());
        successPanel.add(new JLabel("成功列表"),BorderLayout.NORTH);
        successTable.setModel(new SvnCommitCheckTableModel(success));
        successTable.setDefaultEditor(Object.class,new CustomTableCellEditor());
        successPanel.add(new JBScrollPane(successTable),BorderLayout.CENTER);
        add(successPanel);


        JBPanel warnPanel = new JBPanel();
        warnPanel.setLayout(new BorderLayout());
        warnPanel.add(new JLabel("警告列表"),BorderLayout.NORTH);
        warnTable.setModel(new SvnCommitCheckTableModel(warn));
        warnTable.setDefaultEditor(Object.class,new CustomTableCellEditor());
        warnPanel.add(new JBScrollPane(warnTable),BorderLayout.CENTER);
        add(warnPanel);


        JBPanel errorPanel = new JBPanel();
        errorPanel.setLayout(new BorderLayout());
        errorPanel.add(new JLabel("失败列表"),BorderLayout.NORTH);
        errorTable.setModel(new SvnCommitCheckTableModel(error));
        errorTable.setDefaultEditor(Object.class,new CustomTableCellEditor());
        errorPanel.add(new JBScrollPane(errorTable),BorderLayout.CENTER);
        add(errorPanel);
    }

    public List<SvnCommitCheck> getSuccessFiles() {
        return success;
    }
}
